home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / util / light.c next >
Encoding:
C/C++ Source or Header  |  1998-07-13  |  4.6 KB  |  140 lines

  1. #define    LIBQTOOLS_CORE
  2. #define    LIBQBUILD_CORE
  3. #include <libqtools.h>
  4. #include <libqbuild.h>
  5.  
  6. struct memory bspStatic;
  7. struct memory *bspMem = &bspStatic;
  8.  
  9. extern int c_bad;
  10. extern struct tnode *tnodes, *tnode_p;
  11. extern bool *nolightface;
  12. extern float *minlights;
  13. extern float rangescale;
  14. extern float scalecos;
  15. extern float scaledist;
  16. extern int bspfileface;                        /* next surface to dispatch */
  17. extern vec3_t *faceoffset;
  18. extern vec3_t bsp_origin;
  19.  
  20. extern void LightWorld(__memBase);
  21. extern void MakeTnodes(__memBase, register struct dmodel_t *bm);
  22.  
  23. /*
  24.  * ========
  25.  * main
  26.  * 
  27.  * light modelfile
  28.  * ========
  29.  */
  30. int main(int argc, char **argv)
  31. {
  32.   int i;
  33.   char source[NAMELEN_PATH];
  34.   HANDLE bspFile;
  35.   int litOptions = 0;
  36.  
  37.   memset(bspMem, 0, sizeof(struct memory));
  38.  
  39.   if (!setjmp(eabort)) {
  40.     printf("----- LightFaces --------\n");
  41.  
  42.     for (i = 1; i < argc; i++) {
  43.       if (!strcmp(argv[i], "-extra")) {
  44.     litOptions |= LIGHT_EXTRA;
  45.     mprintf("extra sampling enabled\n");
  46.       }
  47.       else if (!strcmp(argv[i], "-rad")) {
  48.     litOptions |= LIGHT_RADIOSITY;
  49.     mprintf("radiosity calculation enabled\n");
  50.       }
  51.       else if (!strcmp(argv[i], "-waterlit")) {
  52.     litOptions |= LIGHT_WATERLIT;
  53.     mprintf("extra watershadowing enabled\n");
  54.       }
  55.       else if (!strcmp(argv[i], "-dist")) {
  56.     scaledist = atof(argv[i + 1]);
  57.     i++;
  58.       }
  59.       else if (!strcmp(argv[i], "-range")) {
  60.     rangescale = atof(argv[i + 1]);
  61.     i++;
  62.       }
  63.       else if (argv[i][0] == '-')
  64.     Error("Unknown option \"%s\"", argv[i]);
  65.       else
  66.     break;
  67.     }
  68.  
  69.     if (i != argc - 1)
  70.       Error("usage: light [-extra] bspfile");
  71.  
  72.     strcpy(source, argv[i]);
  73.     ReplaceExt(source, "bsp");
  74.     if ((bspFile = __open(source, H_READWRITE_BINARY_OLD)) > 0) {
  75.       if ((bspMem = LoadBSP(bspFile, ALL_QUAKE1_LUMPS & ~(LUMP_LIGHTING | LUMP_VISIBILITY), BSP_VERSION_Q1))) {
  76.     bspMem->litOptions = litOptions;
  77.     AllocClusters(bspMem, LUMP_LIGHTING);
  78.  
  79.     if (!(minlights = (float *)kmalloc(sizeof(float) * bspMem->shared.quake1.numfaces)))
  80.         Error("Light: failed to allocate minlights!\n");
  81.  
  82.     if (!(nolightface = (bool *) kmalloc(sizeof(bool) * bspMem->shared.quake1.numfaces)))
  83.       Error("Light: failed to allocate nolightface!\n");
  84.     if (!(faceoffset = (vec3_t *) kmalloc(sizeof(vec3_t) * bspMem->shared.quake1.numfaces)))
  85.       Error("Light: failed to allocate faceoffset!\n");
  86.  
  87.     if (bspMem->litOptions & LIGHT_RADIOSITY) {
  88.       if (!(facepatches = (struct patch **)kmalloc(sizeof(struct patch *) * bspMem->shared.quake1.numfaces)))
  89.           Error("Light: failed to allocate facepatches!\n");
  90.       if (!(faceentity = (struct entity **)kmalloc(sizeof(struct entity *) * bspMem->shared.quake1.numfaces)))
  91.           Error("Light: failed to allocate faceentity!\n");
  92.       if (!(facelights = (struct facelight *)kmalloc(sizeof(struct entity *) * bspMem->shared.quake1.numfaces)))
  93.           Error("Light: failed to allocate facelights!\n");
  94.       if (!(patches = (struct patch *)kmalloc(sizeof(struct patch) * 4096)))
  95.           Error("Light: failed to allocate patches!\n");
  96.  
  97.       if (!(radiosity = (vec3_t *) kmalloc(sizeof(vec3_t) * bspMem->shared.quake1.numfaces)))
  98.         Error("Light: failed to allocate radiosity!\n");
  99.       if (!(illumination = (vec3_t *) kmalloc(sizeof(vec3_t) * bspMem->shared.quake1.numfaces)))
  100.         Error("Light: failed to allocate illumination!\n");
  101.       if (!(backplanes = (struct dplane_t *)kmalloc(sizeof(struct dplane_t) * bspMem->shared.quake1.numplanes)))
  102.           Error("Light: failed to allocate backplanes!\n");
  103.       if (!(directlights = (struct directlight **)kmalloc(sizeof(struct directlight *) * bspMem->shared.quake1.numleafs)))
  104.           Error("Light: failed to allocate directlights!\n");
  105.       if (!(leafparents = (int *)kmalloc(sizeof(int) * bspMem->shared.quake1.numleafs)))
  106.           Error("Light: failed to allocate leafparents!\n");
  107.       if (!(nodeparents = (int *)kmalloc(sizeof(int) * bspMem->shared.quake1.numnodes)))
  108.           Error("Light: failed to allocate nodeparents!\n");
  109.  
  110.       if (!(texreflectivity = (vec3_t *) kmalloc(sizeof(vec3_t) * bspMem->shared.quake1.numtexinfo)))
  111.         Error("Lights: failed to allocate texture reflectivity!\n");
  112.     }
  113.  
  114.     bspMem->mapOptions |= MAP_LOADLIGHTS;
  115.     LoadMapFile(bspMem, bspMem->shared.quake1.dentdata);
  116.     MakeTnodes(bspMem, &bspMem->shared.quake1.dmodels[0]);
  117.  
  118.     if (bspMem->litOptions & LIGHT_RADIOSITY)
  119.       RadWorld(bspMem);
  120.     else
  121.       LightWorld(bspMem);
  122.  
  123.     WriteEntitiesToString(bspMem);
  124.     WriteBSP(bspFile, bspMem, BSP_VERSION_Q1);
  125.     PrintClusters(bspMem, 0, TRUE);
  126.  
  127.     FreeClusters(bspMem, 0);
  128.     kfree();
  129.     __close(bspFile);
  130.       }
  131.       else
  132.     eprintf("failed to load bsp file %s\n", source);
  133.     }
  134.     else
  135.       eprintf("failed to open bsp file %s\n", source);
  136.   }
  137.  
  138.   return 0;
  139. }
  140.